package cn.com.bonc.khjy.utils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 * Created by hanbing on 2019/5/31.
 */
public class CalendarUtil {
    public static Date toShortTimeString(String time,String pattern){
        Date dt=new Date();
        SimpleDateFormat myFmt=new SimpleDateFormat(pattern);//yyyy-MM-dd HH:mm
        try {
            dt=myFmt.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return dt ;
    }
    /**
     *  toShortTimeString
     * @param date date
     * @param pattern pattern
     * @return
     */
    public static String toShortTimeString(Date date,String pattern){
        SimpleDateFormat myFmt=new SimpleDateFormat(pattern);//yyyy-MM-dd HH:mm
        return myFmt.format(date);
    }
    public static  double getDistanceTime(Date startTime, Date endTime) {
        double hour = 0;
        long time1 = startTime.getTime();
        long time2 = endTime.getTime();

        long diff;
        if (time1 < time2) {
            diff = time2 - time1;
        } else {
            diff = time1 - time2;
        }
        hour = (diff / (60 * 60 * 1000));
        return hour;
    }
}
